package retrieval;

import java.io.ByteArrayInputStream;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import utils.Configuration;

public class StreamWrapper
{
    public Document stream2doc(byte[] streams)
    {
        Document doc = null;
        try
        {
            SAXReader reader = new SAXReader();
            ByteArrayInputStream bais = new ByteArrayInputStream(streams);
            doc = reader.read(bais);
        }
        catch (DocumentException e)
        {
            e.printStackTrace();
        }
        return doc;
    }

    public static void save(byte[] streams, String fileName)
    {
        try
        {
            DirWrapper dirWrapper = DirWrapper.getInstance();
            if (!dirWrapper.save(streams, fileName))
            {
                System.err.println("Error in save file of StreamWrapper");
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
